
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
 * Chat.java
 *
 * Created on Jan 27, 2011, 11:36:23 PM
 */

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import java.awt.Toolkit;
import javax.swing.*;
import java.sql.*;

final class Chat extends javax.swing.JInternalFrame {
PreparedStatement statement;
Systems systems=new Systems();
String merchantID="",senderChatAlias="",receiverLoginCode="",chatGroupCode="",chatGroupName="";
    Thread processThread=new Thread();
    Thread titleThread=new Thread();
    /** Creates new form TransactionType */
    public Chat() {
        initComponents();
        senderChatAlias=systems.getValue(OpenMSApp.Database_A, "Select vChatAlias from Login where cLoginCode='"+OpenMSApp.LoginCode+"'", 1);
        reset();
        setTitle("::. Chat - All Users");
        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                while(true)
                {
                    refreshUsers(chatGroupName);
                    updateRead();
                    try{
                    Thread.sleep(1000);
                    }catch(Exception e){System.out.println("Error in chat sleep:"+e);}
                }
            }
        });
        processThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jAddCommentButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jAllCommentTextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jNewCommentTextArea = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jBuzzButton = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();

        setClosable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(Chat.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jAddCommentButton.setFont(resourceMap.getFont("jAddCommentButton.font")); // NOI18N
        jAddCommentButton.setIcon(resourceMap.getIcon("jAddCommentButton.icon")); // NOI18N
        jAddCommentButton.setText(resourceMap.getString("jAddCommentButton.text")); // NOI18N
        jAddCommentButton.setName("jAddCommentButton"); // NOI18N
        jAddCommentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAddCommentButtonActionPerformed(evt);
            }
        });

        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jAllCommentTextArea.setColumns(20);
        jAllCommentTextArea.setEditable(false);
        jAllCommentTextArea.setRows(5);
        jAllCommentTextArea.setWrapStyleWord(true);
        jAllCommentTextArea.setName("jAllCommentTextArea"); // NOI18N
        jScrollPane1.setViewportView(jAllCommentTextArea);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jNewCommentTextArea.setColumns(20);
        jNewCommentTextArea.setRows(5);
        jNewCommentTextArea.setWrapStyleWord(true);
        jNewCommentTextArea.setName("jNewCommentTextArea"); // NOI18N
        jScrollPane2.setViewportView(jNewCommentTextArea);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Alias", "Status"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jTable1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTable1PropertyChange(evt);
            }
        });
        jScrollPane3.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N

        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Group --" }));
        jComboBox1.setEnabled(false);
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                        .addComponent(jButton2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jBuzzButton.setText(resourceMap.getString("jBuzzButton.text")); // NOI18N
        jBuzzButton.setName("jBuzzButton"); // NOI18N
        jBuzzButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBuzzButtonActionPerformed(evt);
            }
        });

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jEditorPane1.setName("jEditorPane1"); // NOI18N
        jScrollPane4.setViewportView(jEditorPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 789, Short.MAX_VALUE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 859, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jAddCommentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jBuzzButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(214, 214, 214))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jAddCommentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jBuzzButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        getAccessibleContext().setAccessibleName(resourceMap.getString("Form.AccessibleContext.accessibleName")); // NOI18N

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jAddCommentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddCommentButtonActionPerformed
        // TODO add your handling code here:
        if(jComboBox1.getSelectedItem().equals("-- Group --")&&jCheckBox1.isSelected())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please select a group","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        else if(jNewCommentTextArea.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please enter a message ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        else
        {
            updateSend();
        }
    }//GEN-LAST:event_jAddCommentButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
        processThread.stop();
    }//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    refreshUsers(chatGroupName);
}//GEN-LAST:event_jButton2ActionPerformed

private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
    if(jCheckBox1.isSelected())
    {
        jComboBox1.setEnabled(true);
        setTitle("::. Chat - Group");
        receiverLoginCode="";
    }
    else
    {
        jComboBox1.setEnabled(false);
        setTitle("::. Chat - All Users");
    }
    resetGroup();
}//GEN-LAST:event_jCheckBox1ActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    if(jComboBox1.getSelectedItem().equals("-- Group --"))
    {
        resetGroup();
        setTitle("::. Chat - Group");
    }
    else
    {
        chatGroupName=jComboBox1.getSelectedItem().toString().trim();
        refreshUsers(jComboBox1.getSelectedItem().toString().trim());
        setTitle("::. Chat - Group ["+jComboBox1.getSelectedItem().toString().trim()+"]");
    }
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTable1PropertyChange

}//GEN-LAST:event_jTable1PropertyChange

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
    if(jCheckBox1.isSelected()==false)
        if(jTable1.getSelectedRow()!=-1)
        {
            receiverLoginCode=systems.getValue(OpenMSApp.Database_A, "Select cLoginCode from Login where vChatAlias='"+jTable1.getValueAt(jTable1.getSelectedRow(), 0)+"'", 1);
            chatGroupCode="";
            chatGroupName="";
            setTitle("::. Chat - All Users ["+jTable1.getValueAt(jTable1.getSelectedRow(), 0)+"]");
            
        }
}//GEN-LAST:event_jTable1MouseClicked

private void jBuzzButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBuzzButtonActionPerformed
    //submitBuzz();
    //submitBuzzData();
    try
    {
    jEditorPane1.print();
    }catch(Exception e){System.out.println("Pane Print error");}
}//GEN-LAST:event_jBuzzButtonActionPerformed

    void resetGroup()
    {
        String[] group=systems.toColumnHeaderWithLead(systems.getColumn(OpenMSApp.Database_A, "Select vName from groups join merchantGroup on Groups.cGroupCode=MerchantGroup.cGroupCode where cMerchantID='"+OpenMSApp.EmployeeID+"'",1));
        group[0]="-- Select --";
        jComboBox1.setModel(new DefaultComboBoxModel(group));
        chatGroupCode="";
            chatGroupName="";
    }
    public void updateSend()
    {
        submitData();
        jNewCommentTextArea.setText("");
        if(jCheckBox1.isSelected())
            jAllCommentTextArea.setText(systems.getValue(OpenMSApp.Database_A, "Select tConversation from chatConversation where cGroupCode='"+chatGroupCode+"'", "tConversation"));
        else
            jAllCommentTextArea.setText(systems.getValue(OpenMSApp.Database_A, "Select tConversation from chatConversation where (cSenderLoginCode = '"+OpenMSApp.LoginCode+"' and cReceiverLoginCode='"+receiverLoginCode+"' and cGroupCode='"+chatGroupCode+"')or(cSenderLoginCode = '"+receiverLoginCode+"' and cReceiverLoginCode='"+OpenMSApp.LoginCode+"' and cGroupCode='"+chatGroupCode+"')", "tConversation"));
        
    }
    synchronized public void updateRead()
    {
        if(!receiverLoginCode.isEmpty()||!chatGroupCode.isEmpty())
        {
            if(jCheckBox1.isSelected())
                jAllCommentTextArea.setText(systems.getValue(OpenMSApp.Database_A, "Select tConversation from chatConversation where cGroupCode='"+chatGroupCode+"'", "tConversation"));
            else
                jAllCommentTextArea.setText(systems.getValue(OpenMSApp.Database_A, "Select tConversation from chatConversation where (cSenderLoginCode = '"+OpenMSApp.LoginCode+"' and cReceiverLoginCode='"+receiverLoginCode+"' and cGroupCode='"+chatGroupCode+"')or(cSenderLoginCode = '"+receiverLoginCode+"' and cReceiverLoginCode='"+OpenMSApp.LoginCode+"' and cGroupCode='"+chatGroupCode+"')", "tConversation"));
            String[] chatBuz=systems.getValue(OpenMSApp.Database_A, "Select cSenderLoginCode,cStatus from chatBuzz where cReceiverLoginCode='"+OpenMSApp.LoginCode+"' and cStatus='0'", 1,2);
            
            if(chatBuz[1]==null?false:chatBuz[1].equalsIgnoreCase("0"))
            {
                jLabel1.setText("Buzz from "+systems.getValue(OpenMSApp.Database_A, "Select vChatAlias from login where cLoginCode='"+chatBuz[0]+"'", 1));
                Toolkit.getDefaultToolkit().beep();
                submitRead();
            }
            else
                jLabel1.setText("");
        }
    }
    synchronized void refreshUsers(String group)
    {
        String groupSyntax="";
        if(group.equals("-- Group --"))
        {            
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                    null,
                new String [] {
                    "Alias", "Status"
                }
            ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });    
            chatGroupCode="";
            chatGroupName="";
        }
        else if(!group.isEmpty())
        {
            chatGroupCode=systems.getValue(OpenMSApp.Database_A, "Select cGroupCode from Groups where vName='"+group+"'", 1);
            groupSyntax="and cEmployeeID in (Select cMerchantID from merchantGroup where cGroupCode='"+chatGroupCode+"')";
        }else {chatGroupCode="";
            chatGroupName="";}
        String[][] users=systems.getColumn(OpenMSApp.Database_A, "Select vChatAlias,cChatStatus from Login where cLoginCode!='"+OpenMSApp.LoginCode+"' and cStatus='Active' "+groupSyntax, 1,2);
        
        if(users==null)return;
        int x=0;
        Object[][] tableObject=new Object[users[1].length][2];
        while(x<users[1].length)
        {
            tableObject[x][0]=users[0][x];
            tableObject[x][1]=users[1][x];
            x++;
        }
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Alias", "Statuss"
            }
        ){
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });    
        systems.freeHeap();
            //Toolkit.getDefaultToolkit().beep();
    }
    public void reset()
    {
        jNewCommentTextArea.setText("");
        jAllCommentTextArea.setText("");
        refreshUsers(jCheckBox1.isSelected()?jComboBox1.getSelectedItem().toString():"");
    }
    synchronized public void submitData()
    {
        Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnAddChat"+Connect.procInitStart+"?,?,?,?"+Connect.procInitEnd);
        try
        {
            statement.setString(1,OpenMSApp.LoginCode);
            statement.setString(2,receiverLoginCode);
            statement.setString(3,chatGroupCode);
            statement.setString(4,senderChatAlias+"\n"+jNewCommentTextArea.getText().trim()+"\n");
        }
        catch(Exception e)
        {
            System.out.println("Note.submitData() gave error ! "+e);
        }
        Connect.alert="N";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    synchronized public void submitBuzzData()
    {
        Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnAddChat"+Connect.procInitStart+"?,?,?,?"+Connect.procInitEnd);
        try
        {
            statement.setString(1,OpenMSApp.LoginCode);
            statement.setString(2,receiverLoginCode);
            statement.setString(3,chatGroupCode);
            statement.setString(4,senderChatAlias+"\n"+"Buzz!"+"\n");
        }
        catch(Exception e)
        {
            System.out.println("Note.submitData() gave error ! "+e);
        }
        Connect.alert="N";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    synchronized public void submitRead()
    {
        Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnUpdChatBuzz"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
            try{
            statement.setString(1,receiverLoginCode);
            statement.setString(2,OpenMSApp.LoginCode);
            }
            catch(Exception e)
            {
            System.out.println("Note.submitRead() gave error ! "+e);
            }
        Connect.alert="N";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    synchronized public void submitBuzz()
    {
        Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnAddChatBuzz"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
            try{
                statement.setString(1,OpenMSApp.LoginCode);
                statement.setString(2,receiverLoginCode);
            }
            catch(Exception e)
            {
            System.out.println("Note.submitBuzz() gave error ! "+e);
            }
        Connect.alert="N";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    @Override
    public void finalize(){
        processThread.stop();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAddCommentButton;
    private javax.swing.JTextArea jAllCommentTextArea;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jBuzzButton;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextArea jNewCommentTextArea;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
